//
//  MenuBar.m
//  QSBK
//
//  Created by Eric Wang on 4/17/15.
//  Copyright (c) 2015 Eric Wang. All rights reserved.
//

#import "MenuBar.h"

@implementation MenuBar
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if(self)
    {
        [self addAllSubViews];
    }
    return self;
}

- (void)addAllSubViews
{
    CGFloat w = self.frame.size.width/6;
    CGFloat h = self.frame.size.height;

    MenuButton *btn1 = [[MenuButton alloc]initWithFrame:CGRectMake(0, 0, w, h)];
    btn1.buttonIndex = 1;
    btn1.selected = YES;
    self.selectedButton = btn1;
    [btn1 setTitle:@"专享" forState:UIControlStateNormal];
    [btn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn1 setTitleColor:[UIColor colorWithRed:254/255.0 green:200/255.0 blue:5/255.0 alpha:1.0]  forState:UIControlStateSelected];
    [btn1 setImage:[UIImage imageNamed:@"menu_selected.png"] forState:UIControlStateSelected];
    [btn1 addTarget:self action:@selector(kindOfQBClick:) forControlEvents:UIControlEventTouchUpInside];
    
    MenuButton *btn2 = [[MenuButton alloc]initWithFrame:CGRectMake(w, 0, w, h)];
    btn2.buttonIndex = 2;
    [btn2 setTitle:@"视频" forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor colorWithRed:254/255.0 green:200/255.0 blue:5/255.0 alpha:1.0]  forState:UIControlStateSelected];
    [btn2 setImage:[UIImage imageNamed:@"menu_selected.png"] forState:UIControlStateSelected];
    [btn2 addTarget:self action:@selector(kindOfQBClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    MenuButton *btn3 = [[MenuButton alloc]initWithFrame:CGRectMake(2*w, 0, w, h)];
    btn3.buttonIndex = 3;
    [btn3 setTitle:@"纯文" forState:UIControlStateNormal];
    [btn3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn3 setTitleColor:[UIColor colorWithRed:254/255.0 green:200/255.0 blue:5/255.0 alpha:1.0]  forState:UIControlStateSelected];
    [btn3 setImage:[UIImage imageNamed:@"menu_selected.png"] forState:UIControlStateSelected];
    [btn3 addTarget:self action:@selector(kindOfQBClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    MenuButton *btn4 = [[MenuButton alloc]initWithFrame:CGRectMake(3*w, 0, w, h)];
    btn4.buttonIndex = 4;
    [btn4 setTitle:@"纯图" forState:UIControlStateNormal];
    [btn4 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn4 setTitleColor:[UIColor colorWithRed:254/255.0 green:200/255.0 blue:5/255.0 alpha:1.0]  forState:UIControlStateSelected];
    [btn4 setImage:[UIImage imageNamed:@"menu_selected.png"] forState:UIControlStateSelected];
    [btn4 addTarget:self action:@selector(kindOfQBClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    MenuButton *btn5 = [[MenuButton alloc]initWithFrame:CGRectMake(4*w, 0, w, h)];
    btn5.buttonIndex = 5;
    [btn5 setTitle:@"精华" forState:UIControlStateNormal];
    [btn5 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn5 setTitleColor:[UIColor colorWithRed:254/255.0 green:200/255.0 blue:5/255.0 alpha:1.0]  forState:UIControlStateSelected];
    [btn5 setImage:[UIImage imageNamed:@"menu_selected.png"] forState:UIControlStateSelected];
    [btn5 addTarget:self action:@selector(kindOfQBClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    MenuButton *btn6 = [[MenuButton alloc]initWithFrame:CGRectMake(5*w, 0, w, h)];
    btn6.buttonIndex = 6;
    [btn6 setTitle:@"最新" forState:UIControlStateNormal];
    [btn6 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn6 setTitleColor:[UIColor colorWithRed:254/255.0 green:200/255.0 blue:5/255.0 alpha:1.0]  forState:UIControlStateSelected];
    [btn6 setImage:[UIImage imageNamed:@"menu_selected.png"] forState:UIControlStateSelected];
    [btn6 addTarget:self action:@selector(kindOfQBClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:btn1];
    [self addSubview:btn2];
    [self addSubview:btn3];
    [self addSubview:btn4];
    [self addSubview:btn5];
    [self addSubview:btn6];
}


-(void)kindOfQBClick:(MenuButton *)button
{
    button.selected = YES;
    self.selectedButton.selected = NO;
    self.selectedButton = button;
    if(self.delegate!=nil&&[self.delegate respondsToSelector:@selector(didChooseMenuOnButtonIndex:)])
    {
        [self.delegate didChooseMenuOnButtonIndex:button.buttonIndex];
    }
}
@end
